package view;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.border.EtchedBorder;

import model.Student;
import dao.MydbOper;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class InsertPanel extends JPanel {
	private JLabel label;
	private JTextField idTxt;
	private JLabel label_1;
	private JTextField nameTxt;
	private JLabel label_2;
	private JTextField mathTxt;
	private JLabel label_3;
	private JTextField physiTxt;
	private JLabel label_4;
	private JTextField englishTxt;
	private JButton addButton;
	MydbOper mydbOper=new MydbOper();
	/**
	 * Create the panel.
	 */
	public InsertPanel() {
		setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		setLayout(null);
		
		label = new JLabel("\u5B66\u53F7\uFF1A");
		label.setBounds(36, 44, 54, 15);
		add(label);
		
		idTxt = new JTextField();
		idTxt.setColumns(10);
		idTxt.setBounds(100, 44, 88, 21);
		add(idTxt);
		
		label_1 = new JLabel("\u59D3\u540D\uFF1A");
		label_1.setBounds(198, 47, 54, 15);
		add(label_1);
		
		nameTxt = new JTextField();
		nameTxt.setColumns(10);
		nameTxt.setBounds(262, 44, 96, 21);
		add(nameTxt);
		
		label_2 = new JLabel("\u6570\u5B66\u6210\u7EE9\uFF1A");
		label_2.setBounds(36, 85, 65, 15);
		add(label_2);
		
		mathTxt = new JTextField();
		mathTxt.setColumns(10);
		mathTxt.setBounds(100, 85, 88, 21);
		add(mathTxt);
		
		label_3 = new JLabel("\u7269\u7406\u6210\u7EE9\uFF1A");
		label_3.setBounds(198, 88, 65, 15);
		add(label_3);
		
		physiTxt = new JTextField();
		physiTxt.setColumns(10);
		physiTxt.setBounds(262, 85, 96, 21);
		add(physiTxt);
		
		label_4 = new JLabel("\u82F1\u8BED\u6210\u7EE9\uFF1A");
		label_4.setBounds(36, 127, 65, 15);
		add(label_4);
		
		englishTxt = new JTextField();
		englishTxt.setColumns(10);
		englishTxt.setBounds(100, 127, 88, 21);
		add(englishTxt);
		
		addButton = new JButton("\u4FDD\u5B58");
		addButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				addButtonActionPerformed(e);
			}
		});
		addButton.setBounds(265, 126, 93, 23);
		add(addButton);

	}

	protected void addButtonActionPerformed(ActionEvent e) {
		String id=idTxt.getText().trim();
		String name=nameTxt.getText().trim();
		float  math=Float.parseFloat(mathTxt.getText().trim());
		float physical=Float.parseFloat(physiTxt.getText().trim());
		float english=Float.parseFloat(englishTxt.getText().trim());
		Student s=new Student(id, name, math, physical, english);
		mydbOper.insert(s);
		idTxt.setText("");
		nameTxt.setText("");
		mathTxt.setText("");
		physiTxt.setText("");
		englishTxt.setText("");
		
	}
}
